package yawning.mew.cat;

import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class EventTigersFury extends SimulationEventAction {
	CatModelSimState mState;
	double mCooldownAt;

	EventTigersFury(CatModelSimState state) {
		super(state.mSimEngine);
		mState = state;
	}

	@Override
	public double perform() {
		if (isUp() || mCooldownAt > mState.mSimEngine.getSimTime() || mState.mBerserkEv.isUp()) return SimulationAction.ACTION_FAIL;

		if (mState.mIsLogging) mState.mLog.log("Tiger's Fury\n");

		mNrTF++;

		mState.mTigersFuryEv.schedule(mState.mModel.tigersFuryBuffDuration);
		if (mState.mModel.kotjEnergyGain > 0) {
			int prevEnergy = mState.getEnergy();

			mKotJEnergyGained += mState.mModel.kotjEnergyGain;
			mState.mEnergyTickEv.onEnergyGain(mState.mModel.kotjEnergyGain);

			mState.logEnergyChange(prevEnergy);
		}
		mCooldownAt = mState.mSimEngine.getSimTime() + mState.mModel.tigersFuryCDDuration;

		mState.onPrimalMadnessGain();

		if (mState.mModel.druid.tier_13_4pc) mState.mStampedeEv.run();

		return 0.0f;
	}

	@Override
	public void onExpire() {
		if (mState.mIsLogging) mState.mLog.log("Tiger's Fury: Expiration\n");

		mState.onPrimalMadnessLoss(false);
	}

	int mNrTF = 0;
	long mKotJEnergyGained;
}